/*
 * Project it.battlehorse.rcp.tools
 * Created on Nov 18, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */
package it.battlehorse.rcp.tools.views.actorlist;

import it.battlehorse.rcp.tools.actors.ActorDescriptor;
import it.battlehorse.rcp.tools.actors.IActorConstants;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * Defines the label provider for the actors list view.
 * 
 * @author battlehorse
 * @since Nov 18, 2005
 */
public class ActorListLabelProvider implements ITableLabelProvider, IActorConstants, ILabelProvider {
	
	private ImageRegistry registry;

	
	public ActorListLabelProvider() {
		registry = new ImageRegistry();		
	}
	
    public String getColumnText(Object obj, int index) {
        return getText(obj);

    }
    
    public Image getColumnImage(Object obj, int index) {
        return getImage(obj);
        	
    }
    
    public String getText(Object obj) {
    	ActorDescriptor conf = (ActorDescriptor) obj;
    	return conf.getName();  	
    }
    
    public Image getImage(Object obj) {
    	ActorDescriptor conf = (ActorDescriptor) obj;    	
    	String id = conf.getId();
    	Image im = registry.get(id);
    	if (im == null) {
    		ImageDescriptor d = conf.getIcon();
    		registry.put(id, d);
    		im = registry.get(id);
    	}    	
    	return im;
    }
        
	public void addListener(ILabelProviderListener listener) {
		// Ignore, nothing to notify@Serviceable

	}

	public void dispose() {
		registry.dispose();
	}

	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
		// Ignore, nothing to notify

	}
}